package edu.online.dal;

import edu.online.entity.CourseEntity;
import org.apache.ibatis.jdbc.SQL;

public class CourseEntitySqlProvider {

    public String insertSelective(CourseEntity record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("course");
        
        if (record.getCourseid() != null) {
            sql.VALUES("CourseID", "#{courseid,jdbcType=CHAR}");
        }
        
        if (record.getCoursename() != null) {
            sql.VALUES("CourseName", "#{coursename,jdbcType=VARCHAR}");
        }
        
        if (record.getSubid() != null) {
            sql.VALUES("SubID", "#{subid,jdbcType=CHAR}");
        }
        
        if (record.getLessonnum() != null) {
            sql.VALUES("LessonNum", "#{lessonnum,jdbcType=SMALLINT}");
        }
        
        if (record.getPrice() != null) {
            sql.VALUES("Price", "#{price,jdbcType=SMALLINT}");
        }
        
        if (record.getComment() != null) {
            sql.VALUES("Comment", "#{comment,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(CourseEntity record) {
        SQL sql = new SQL();
        sql.UPDATE("course");
        
        if (record.getCoursename() != null) {
            sql.SET("CourseName = #{coursename,jdbcType=VARCHAR}");
        }
        
        if (record.getSubid() != null) {
            sql.SET("SubID = #{subid,jdbcType=CHAR}");
        }
        
        if (record.getLessonnum() != null) {
            sql.SET("LessonNum = #{lessonnum,jdbcType=SMALLINT}");
        }
        
        if (record.getPrice() != null) {
            sql.SET("Price = #{price,jdbcType=SMALLINT}");
        }
        
        if (record.getComment() != null) {
            sql.SET("Comment = #{comment,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("CourseID = #{courseid,jdbcType=CHAR}");
        
        return sql.toString();
    }
}